<?php
namespace Human\Controller;
use Admin\Controller\AdminController;
/**
 * 职务管理
 */

class JobController extends AdminController {
    /**
     * 当前模块参数
     */
    protected function _infoModule(){
        return array(
            'info'  => array(
                'name' => '所有职务',
                'description' => '管理职务',
                ),
            'menu' => array(
                array('name' => '职务列表',
                    'url' => U('Human/job/index'),
                    'icon' => 'list',
                    ),
                ),
            'add' => array(
                array('name' => '添加职务',
                    'url' => U('add'),
                    ),
                ),
            );
    }
	/**
     * 职务
     */
    public function index(){
        $breadCrumb = array('职务列表' => U());
        $this->assign('breadCrumb', $breadCrumb);
        $count = D('Job')->countList();
        $limit = $this->getPageLimit($count,10);
        $this->assign('list', D('Job')->loadList($map,$limit)); 
        $this->assign('page',$this->getPageShow($pageMaps));
        $this->adminDisplay();
    }

    /**
     * 增加
     */
    public function add()
    {
        if (!IS_POST)
        {
            $breadCrumb = array('职务列表' => U('index'), '职务添加' => U());
            $this->assign('breadCrumb', $breadCrumb);
            $model = D('Human/Department');
            $departmentList = $model ->loadList();
            $this->assign('departmentList', $departmentList);
            $this->assign('name', '添加');
            $this->adminDisplay('info');
        }
        else
        {
            $model = D('Job');
            $where['job_name']=array('eq',trim($_POST['job_name']));
            $where['department_id']=array('eq',intval($_POST['department_id']));
            if($model->getWhereInfo($where)){
                $this->error('当前部门已存在改职务');
            }
            if ($model->saveData('add'))
            {
                $this->success('职务添加成功！');
            }
            else
            {
                $msg = $model->getError();
                if (empty($msg))
                {
                    $this->error('职务添加失败');
                }
                else
                {
                    $this->error($msg);
                }
            }
        }
    }

    /**
     * 修改
     */
    public function edit()
    {
        $model = D('Job');
        if (!IS_POST)
        {
            $jobId = I('get.job_id', '', 'intval');
            if (empty($jobId))
            {
                $this->error('参数不能为空！');
            }
            $info = $model->getInfo($jobId);
            if (!$info)
            {
                $this->error($model->getError());
            }
            $breadCrumb = array('职务列表' => U('index'), '职务修改' => U('edit', array('fieldset_id' => $fieldsetId)));
            $this->assign('breadCrumb', $breadCrumb);
            $model = D('Human/Department');
            $departmentList = $model ->loadList();
            $this->assign('departmentList', $departmentList);
            $this->assign('name', '修改');
            $this->assign('info', $info);
            $this->adminDisplay('info');
        }
        else
        {
            if ($model->saveData('edit'))
            {
                $this->success('职务列表修改成功！');
            }
            else
            {
                $msg = $model->getError();
                if (empty($msg))
                {
                    $this->error('职务列表修改失败');
                }
                else
                {
                    $this->error($msg);
                }
            }
        }
    }

    /**
     * 删除
     */
    public function del()
    {
        $jobId = I('post.data');
        if (empty($jobId))
        {
            $this->error('参数不能为空！');
        } 
        // 删除操作
        $model = D('Job');
        if ($model->delData($jobId))
        {
            $this->success('职务删除成功！');
        }
        else
        {
            $msg = $model->getError();
            if (empty($msg))
            {
                $this->error('职务删除失败！');
            }
            else
            {
                $this->error($msg);
            }
        }
    }

}

